package com.wangyadong.hobby.nio.charter1.bytebuffer;

import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class ByteBufferTest {

    public static void main(String[] args) throws IOException {
        FileChannel channel = new RandomAccessFile("D:\\data\\job-task\\jobhandler\\job-task.log", "rw").getChannel();
//        FileChannel channel = new FileOutputStream("D:\\data\\job-task\\jobhandler\\job-task.log").getChannel();
        ByteBuffer allocate = ByteBuffer.allocate(48);
        int byteRead = -1;
        do {
            byteRead = channel.read(allocate);
            if (byteRead != -1) {
                allocate.flip();
                while (allocate.hasRemaining()) {
                    System.out.println((char) allocate.get());
                }
                allocate.clear();
            }
        } while (byteRead != -1);


    }
}
